import axios from '../../utils/http';
import { observable, action } from 'mobx';
class ClassMobx {
  @observable classForm = {
    goodsCname: '' /* 分类名称 */,
    goodsCnu: '千克' /* 数量单位 */,
    goodsCsort: 50 /* 商品分类排序 */,
    goodsCstatus: '1' /* 商品分类显示状态 */,
    goodsKw: '' /* 关键字*/,
    goodsCm: '' /* 分类描述 */,
    file: '' /* 商品分类图片 */,
    goodPid: '0' /* 父级分类id */,
  };
  @action formChange = (name, val) => {
    this.classForm[name] = val;
  };
  @action classSubmit = () => {
    let form = new FormData();
    form.append('goodsCname', this.classForm.goodsCname);
    form.append('goodsCnu', this.classForm.goodsCnu);
    form.append('goodsCsort', this.classForm.goodsCsort);
    form.append('goodsCstatus', this.classForm.goodsCstatus);
    form.append('goodsKw', this.classForm.goodsKw);
    form.append('goodsCm', this.classForm.goodsCm);
    form.append('file', this.classForm.file);
    form.append('goodPid', this.classForm.goodPid);
    return axios({
      url: '/mm-goods/goods/addGoodsClass',
      method: 'post',
      data: form,
    }).then(({ data }) => {
      if (data.code === 200) {
        this.resetClassForm();
      }
      return data;
    });
  };
  @action resetClassForm = () => {
    this.classForm.goodsCname = '';
    this.classForm.goodsCnu = '千克';
    this.classForm.goodsCsort = 50;
    this.classForm.goodsCstatus = '1';
    this.classForm.goodsKw = '';
    this.classForm.goodsCm = '';
    this.classForm.file = '';
    this.classForm.goodPid = '';
  };
}
export default ClassMobx;
